package com.sandasai.action.authority;

import javax.annotation.Resource;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.sandasai.service.UserManager;

public class DownloadAuthorityInterceptor extends AbstractInterceptor {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Resource
	private UserManager userManager;
	
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		ActionContext ctx = ActionContext.getContext();
        Integer userType = (Integer)ctx.getSession()
                .get("userType");
        String username = (String)ctx.getSession()
        		.get("username");
        String fileName = (String)ctx.get("fileName");
        if(userManager.isAccessible(userType, username, fileName)) {
        	return invocation.invoke();
        }else {
        	return Action.ERROR;
        }
	}

}
